You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the stream reported by the Tracing.tracingComplete event
Motivation
Ferrum requests stream-based output from CDP for PDF generation and tracing.It reads each stream with IO.read until EOF, but does not close the stream handle afterward.
For PDF generation, the handle is returned by Page.printToPDF. For tracing, the handle is delivered through the Tracing.tracingComplete event after Tracing.end is called.
CDP provides IO.close to release a stream handle and discard any temporary backing storage associated with it. Explicitly closing the stream after use keeps its lifecycle well-defined and avoids relying on implicit browser-side cleanup.
This affects streams used by:
Ferrum::Browser#pdf
Ferrum::Page::Tracing#record
Error handling
IO.close is called from an ensure block, so cleanup is attempted when:
the stream reaches EOF
IO.read fails
writing to the output fails
If reading or writing has already failed, an IO.close error is suppressed so that it does not replace the original exception.If the stream was read successfully, an IO.close error is propagated to the caller.
Tests
Added unit tests covering:
reading multiple chunks until EOF
Base64-encoded chunks
IO.read failures
closing after EOF
closing after output write failures
preserving the original read/write exception when closing also fails
preserving non-StandardError exceptions
propagating an IO.close failure after a successful read
Page::Stream#stream previously returned nil as an incidental result of the loop. The completion flag introduced here makes it return true. Its current callers ignore the return value, and its RBS return type is untyped. Is this acceptable, or would you prefer preserving nil?
When IO.read fails with a timeout, the synchronous IO.close attempted by the ensure block may wait for another timeout period. I kept the close synchronous so that cleanup is attempted consistently. Would you prefer a different policy for TimeoutError or DeadBrowserError?
I guess I don't like putting it into ensure, have you tried adding explicit close at the end instead of a flag and a rescue branch? The close method should be public. Though also not clear to me what kind of issues can be raised, I never liked putting rescue StandardError just as a safe guard, it's way too broad.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Close CDP streams with
IO.closeafter reading:Page.printToPDFTracing.tracingCompleteeventMotivation
Ferrum requests stream-based output from CDP for PDF generation and tracing.It reads each stream with
IO.readuntil EOF, but does not close the stream handle afterward.For PDF generation, the handle is returned by
Page.printToPDF. For tracing, the handle is delivered through theTracing.tracingCompleteevent afterTracing.endis called.CDP provides
IO.closeto release a stream handle and discard any temporary backing storage associated with it. Explicitly closing the stream after use keeps its lifecycle well-defined and avoids relying on implicit browser-side cleanup.This affects streams used by:
Ferrum::Browser#pdfFerrum::Page::Tracing#recordError handling
IO.closeis called from anensureblock, so cleanup is attempted when:IO.readfailsIf reading or writing has already failed, an
IO.closeerror is suppressed so that it does not replace the original exception.If the stream was read successfully, anIO.closeerror is propagated to the caller.Tests
Added unit tests covering:
IO.readfailuresStandardErrorexceptionsIO.closefailure after a successful read